home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / xrf.arc / XRF3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-04-20  |  6.3 KB  |  162 lines

  1. /*
  2.  *                      ***************
  3.  *                      * X R F 3 . C *
  4.  *                      ***************
  5.  *
  6.  * Sorted cross reference listing routines. 'prtree' performs an
  7.  * inorder traversal of the id tree, printing the references to'
  8.  * each id while visting that node.
  9.  *
  10.  * Version V1.3          9-May-80
  11.  * Version V1.4        10-Jul-80 MM    Bummed code, added 80 col. support
  12.  * Version V1.5          2-Dec-84 MC    Tweak for CI86 on Msdos Rainbow
  13.  *                       7-Jan-85 MC    Remove case sensitive printing order
  14.  * Version V1.17     5-Apr-85 MC    Add possibility if disk merge.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "xrf.h"
  19.  
  20. static char lk[KEYSIZE+1];    /* used for key compare */
  21. static char *bp;        /* buffer pointer */
  22. static int  rcntr;        /* refs on line counter */
  23. static char keyname[9];        /* program name for this symbol */
  24. static struct BUFR *t;
  25. extern struct BUFR *wrmatch();
  26.  
  27.  
  28. printree(link)
  29. struct idt *link;
  30. { struct dsk *tr;
  31.     totalprint("M Phase ",lintot,namtot,reftot); /* verbosity */
  32.     lintot=namtot=reftot=0;
  33.     newpage();                /* new page */
  34.     wrfix(polroot);                     /* fix mdn fchain in place */
  35.     setmem(lk,KEYSIZE,0xFF);
  36.     bp=scanbf;
  37.     rcntr=0;
  38.     setmem(lastsym,'\0',CPS+1);
  39.     prtree(link);                       /* Print the index */
  40.     setmem(link->keyp,KEYSIZE,0xFF);    /* use as scratch area */
  41.     link->first=-1;
  42.     while((t=wrmatch(polroot,link,link->first))!=NULL)
  43.     putref(t->b_key,t->b_ref,scanbf);    /* ensure disk files exhausted */
  44.     *bp = '\0';                         /* Terminate with null */
  45.     lstrefs();                          /* Write the line out */
  46.     wrkill();                /* kill chain */
  47.     if((polroot=polcurr=wropen(wfilno=1))==NULL)/* open 1st file now as there*/
  48.     abort("XRF3 can't open work disk\n");   /* won't be room when needed */
  49. }
  50.  
  51. /*
  52.  * Inorder tree traversal.
  53.  */
  54.  
  55. prtree(link)
  56. struct idt *link;
  57. {
  58.    if (link != NULL){
  59.       prtree(link->left);       /* Visit the left */
  60.       prtrefs(link);            /* Print refs for this one */
  61.       prtree(link->right);      /* Visit the right */
  62.       }
  63. }
  64.  
  65. /*
  66.  * List out a line of references.
  67.  * Start new page if it gets full.
  68.  */
  69.  
  70. lstrefs()
  71. {
  72.    if(++linpg > MAXLIN)                 /* New page if necessary */
  73.       nwpage();
  74.    fputs(scanbf, lst);                  /* Write out the string */
  75.    fputs("\n", lst);
  76.    rcntr = 0;                           /* Reset refs-on-line count */
  77. }
  78.  
  79. /*
  80.  * Print id and references.
  81.  * Share scan buffer for printout.
  82.  * Use newpag.
  83.  *
  84.  * The ref line number field width is hard-wired into the format statement.
  85.  * Trouble is, #define's don't (and shouldn't!) substitute into strings,
  86.  * like formats.
  87.  *
  88.  * Current values are 5 char field (RSIZE) and rperline ref's per line.
  89.  *
  90.  * The node is now positioned in the tree in case non-sensitive order.
  91.  * This means that in the final list mixed, upper & lower case symbols
  92.  * appear togethor instead of being separated in the collating sequence.
  93.  *
  94.  * The id (*kp) now comes as <KEYactualNNNNNNNN> from XRF0.C where:-
  95.  *                      KEY                is the symbol as lower case
  96.  *                                                  length CPS characters.
  97.  *                               actual          is the symbol as she appears
  98.  *                                                  length CPS characters.
  99.  *                           NNNNNNNN  is the program name
  100.  *                                                  length 8 chars
  101.  * Be aware that this is now a merge function in case memory disk files
  102.  * are present.
  103.  */
  104.  
  105. prtrefs(link)
  106. struct idt *link;
  107. { struct ref *r = link->first;           /* Ref chain pointer */
  108.    do{                                  /* Process Reference line numbers */
  109.     if((t=wrmatch(polroot,link,r))==NULL){
  110.         putref(link->keyp,r->lno,scanbf); /* process memory */
  111.         r = r->next;                      /* (On down the chain) */
  112.         }
  113.     else {
  114.       putref(t->b_key,t->b_ref,scanbf);      /* else process this one */
  115.       }
  116.       } while(r != NULL);                    /* Until the end */
  117. }
  118.  
  119. static putref(nk,ref,p)        /* build reference line */
  120. char *nk;                /* nk --> key */
  121. int ref;                /* reference */
  122. char *p;                /* p  --> start of scan buffer */
  123. { int i;
  124.     if(strcmp(nk,lk)){                          /* if key hange ... */
  125.          if(rcntr){                             /* if any residue ... */
  126.              *bp = '\0';                        /* Terminate with null */
  127.              lstrefs();                         /* Write it out */
  128.              bp=p;                              /* reset buffer pointer */
  129.              rcntr = 0;                         /* Reset refs-on-line count */
  130.              }
  131.          strcpy(lk,nk);
  132.          rcntr = 0;                             /* Init refs-per-line */
  133.          strcpy(keyname,nk+CPS+CPS);            /* Pull out Program Name */
  134.          if(strncmp(nk+CPS,lastsym,CPS)){        /* if Symbol changed ... */
  135.              strncpy(bp,nk+CPS,CPS);            /* put the id string */
  136.              bp += CPS;
  137.              strncpy(lastsym,nk+CPS,CPS);       /* save as previous */
  138.              lastsym[CPS]=EOS;
  139.              }
  140.          while(bp < &scanbf[CPS])*bp++ = ' ';   /* Pad with blanks */
  141.          *bp++ = ':';                           /* Followed by a separator */
  142.          if(conflg){                /* Followed by progname    */
  143.         for(i=0;i<8;*bp++=keyname[i++]);
  144.         *bp++ = ' ';                        /* Followed by a space */
  145.         }
  146.          }
  147.     if(rcntr >= rperline){                      /* If this line is full */
  148.          *bp = '\0';                            /* Terminate with null */
  149.          lstrefs();                             /* Write it out */
  150.          rcntr = 0;                             /* Reset refs-on-line count */
  151.          for(bp=scanbf;bp<&scanbf[CPS];*bp++ =' '); /*Reset buffer ptr*/
  152.          *bp++ = ':';                           /* plus a separator */
  153.          if(conflg){                /* Followed by progname    */
  154.             for(i=0;i<8;*bp++=keyname[i++]);
  155.             *bp++ = ' ';                        /* Followed by a space */
  156.             }
  157.          }
  158.     rcntr++;
  159.     sprintf(bp,"%5d", ref);                     /* Insert ref into buffer */
  160.     bp += RSIZE;                                /* Update buffer pointer */
  161. }
  162.